<?php


namespace Home\Controller;


use Think\Controller;

class ShopController extends PublicController
{
    public function __construct(){
        parent::__construct();
    }

    public function index(){
        $id = I('get.id');

        $page = I('post.page');
        $pagesize = 50;

        if ($page == null) {
            $page = 1;
        }

        $where = "a.status = 2 and a.is_show = 1";

        if ($id != "") {
            $where .= " and a.user_id = ".$id;
        }
        $type_id = I('post.type_id');
        if ($type_id!=""&&$type_id!=0&&$type_id!=null) {
            $where .= " and a.type_id = ".$type_id;
        }
        $find_type=I('post.find_type');
        $search_like = I('post.search_like');
        if($find_type == 1 && $search_like != ""){
            $where.=' and a.name like "%'.$search_like.'%"';
        }
        $active_name=I('post.active_name');
        $order='id asc';
        if($active_name == 2){
            $order='sell_number desc';
        }else if($active_name == 3){
            //评分暂无
        }
        $data = M('goods as a')
            ->join('left join type as b on a.type_id = b.id')->where($where)->field('a.* , b.name as type_name')->order($order)->page($page,$pagesize)->select();
        $data = D('Goods')->parse_goods($data);
        $this->data=$data;
        $this->display();
    }

}